package server.user.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RegController {

    @PostMapping("reg")
    public SaResult reg(@RequestParam(required = false) String username, @RequestParam(required = false) String password) {
        if (StrUtil.isBlank(username)) {
            return SaResult.error("注册用户名不能为空");
        }
        if (StrUtil.isBlank(password)) {
            return SaResult.error("注册密码不能为空");
        }
        StpUtil.login(10001);
        SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
        return SaResult.ok("登录成功！").setData(tokenInfo);
    }

}
